package GPA;
import java.util.ArrayList;
import java.util.List;

public class Student {
    private String studentId;    // 学号
    private String name;         // 姓名
    private String className;    // 班级
    private List<Score> scores;  // 学生的成绩列表

    public Student(String studentId, String name, String className) {
        this.studentId = studentId;
        this.name = name;
        this.className = className;
        this.scores = new ArrayList<>();
    }

    // 添加成绩
    public void addScore(Score score) {
        scores.add(score);
    }

    // 查询某课程的成绩
    public double queryCourseScore(String courseId) {
        for (Score score : scores) {
            if (score.getCourse().getCourseId().equals(courseId)) {
                return score.getScore();
            }
        }
        return -1; // 表示未找到该课程成绩
    }

    // 计算GPA（假设：A=4.0(90-100)、B=3.0(80-89)、C=2.0(70-79)、D=1.0(60-69)、F=0(0-59)）
    public double calculateGPA() {
        double totalGradePoints = 0;
        double totalCredits = 0;

        for (Score score : scores) {
            double scoreValue = score.getScore();
            double credit = score.getCourse().getCredit();
            totalCredits += credit;

            if (scoreValue >= 90) {
                totalGradePoints += 4.0 * credit;
            } else if (scoreValue >= 80) {
                totalGradePoints += 3.0 * credit;
            } else if (scoreValue >= 70) {
                totalGradePoints += 2.0 * credit;
            } else if (scoreValue >= 60) {
                totalGradePoints += 1.0 * credit;
            } else {
                totalGradePoints += 0 * credit;
            }
        }

        return totalCredits == 0 ? 0 : totalGradePoints / totalCredits;
    }

    // Getter 和 Setter 方法
    public String getStudentId() {
        return studentId;
    }

    public void setStudentId(String studentId) {
        this.studentId = studentId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public List<Score> getScores() {
        return scores;
    }

    public void setScores(List<Score> scores) {
        this.scores = scores;
    }
}